package com.lgy.controller;

import com.lgy.pojo.Employee;
import com.lgy.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private IEmployeeService employeeService;

//    @RequestMapping("/goMain.do")
//    public String goMain(Model model, @RequestParam("empId") Integer  empid){
//        model.addAttribute("emp",employeeService.selectByPrimaryKey(empid));
//        return "AdminMain";
//    }


    @RequestMapping("/goMain.do")
    public String goMain(HttpServletRequest request, @RequestParam("empId") Integer  empid){
        Employee employee = employeeService.selectByPrimaryKey(empid);
        request.getSession().setAttribute("emp",employee);
        if(employee.getPositionid()==1){
            return "redirect:/login/toMain.do";
        }
        return "redirect:/login/toEmpMain.do";
    }

    @RequestMapping("/toMain.do")
    public String toMain(){
        return "AdminMain";
    }

    @RequestMapping("/toEmpMain.do")
    public String toEmpMain(){
        return "EmpMain";
    }


    //toLogin
    @RequestMapping("/toLogin.do")
    public String toLogin(HttpSession session){
        session.invalidate();
        return "login";
    }
}
